package controllers

import (
	//"fmt"
	"jiabo/appframework/libs/common"
	"jiabo/appframework/libs/wiki"
)

type WikiController struct {
	RootController
}

func (this *WikiController) Get() {

	this.CheckSession()

	this.Ctx.Request.ParseForm()
	title := this.GetString("wiki")
	if title == "" {
		title = `一切从这里开始`
	}
	if title != "" {
		wikis, _ := wiki.GetWikiByTitle(title)
		if len(wikis) > 0 {
			this.Data["title"] = title
			content := wikis[0].Content
			content = common.ReplaceHtml(content)
			content = common.ConvertFromWikiToHtml(content)
			this.Data["fullname"] = this.GSession("fullname")
			this.Data["m1"] = "arrow"
			this.Data["m2"] = "arrow"
			this.Data["m3"] = "arrow"
			this.Data["m4"] = "arrow"
			this.Data["m5"] = "selected"
			this.Data["m55"] = "start active"
			this.Data["content"] = content
			this.Data["log"] = wikis[0].Log[0 : len(wikis[0].Log)-5]
			this.Data["edittitle"] = title
		} else {
			this.Ctx.Redirect(302, "/edit/?wiki="+title)
		}
	}

	this.Layout = "layout.html"
	this.TplNames = "wiki.html"

}
